Recession Analysis¶

A recession occurs when there are two consecutive quarters of reduced economic activity, marked by a decline in the flow of money in the economy. This drop in spending by people leads to losses for businesses, causing an economic slowdown, job cuts, and the familiar scenario of layoffs that garnered attention in 2023. Recession is typically assessed by examining factors such as GDP growth, changes in the unemployment rate, and fluctuations in consumer spending. However, the predominant method for gauging recession involves scrutinizing monthly GDP growth data. To conduct a thorough recession analysis, it is essential to possess a dataset specifically focused on the monthly GDP growth rates of a given country. In this case, I have identified an ideal dataset centered on the monthly GDP growth rate of the United Kingdom. You can download the dataset here.¶

In [1]:
# Load the dataset
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px
import plotly.io as pio
pio.templates.default = "plotly_white"

data = pd.read_csv("E:\\Portfolio_projects\\Python\\UK_monthly_gdp.csv")
data.head()
Out[1]:
Time Period GDP Growth
0 /01/2020 0.3
1 /02/2020 -0.5
2 /03/2020 -7.0
3 /04/2020 -20.9
4 /05/2020 3.2
In [2]:
fig = px.imshow(data['GDP Growth'].to_frame().T,
                x=data.index,
                y=['GDP Growth'],
                color_continuous_scale='Viridis',
                labels={'x': 'Time Period'},
                title='GDP Growth over Time')

fig.update_xaxes(type='category')

fig.show()

To assess the recession, characterized by a two consecutive quarter decline in the circulation of money, I will convert our monthly data into quarterly data for analysis.¶

In [4]:
# Convert monthly data to quarterly data
data['Time Period'] = pd.to_datetime(data['Time Period'], format='/%m/%Y')
data.set_index('Time Period', inplace=True)

# Resample and take the mean for quarterly data
quarterly_data = data.resample('Q').mean()

print(quarterly_data.head())
             GDP Growth
Time Period            
2020-03-31    -2.400000
2020-06-30    -2.900000
2020-09-30     3.500000
2020-12-31     0.200000
2021-03-31     0.033333
In [8]:
# Calculate recession based on quarterly GDP growth
quarterly_data['Recession'] = ((quarterly_data['GDP Growth'] < 0) & (quarterly_data['GDP Growth'].shift(1) < 0))

# Fill missing values with False (since the first quarter cannot be in a recession)
quarterly_data['Recession'].fillna(False, inplace=True)

# Plot the GDP growth and recession data
fig = go.Figure()
fig.add_trace(go.Scatter(x=quarterly_data.index, 
                         y=quarterly_data['GDP Growth'], 
                         name='GDP Growth', 
                         line=dict(color='green', width=2)))
fig.add_trace(go.Scatter(x=quarterly_data[quarterly_data['Recession']].index, 
                         y=quarterly_data[quarterly_data['Recession']]['GDP Growth'], 
                         name='Recession', line=dict(color='red', width=2)))

fig.update_layout(title='GDP Growth and Recession over Time (Quarterly Data)',
                  xaxis_title='Time Period',
                  yaxis_title='GDP Growth')

fig.show()

The red line indicates intervals of negative GDP growth, representing recessions, while the green line illustrates the broader trend of GDP growth over time.¶

Now, let's assess the intensity of the recession. The severity of a recession pertains to the degree of economic contraction experienced during this period. A severe recession signifies a more profound and extended downturn in economic activity, leading to adverse impacts on employment, incomes, and various other economic indicators.¶

In [9]:
# Create a boolean mask for recession periods
quarterly_data['Recession Start'] = quarterly_data['Recession'].ne(quarterly_data['Recession'].shift()).cumsum()

# Calculate recession duration and severity
recession_data = quarterly_data.groupby('Recession Start').agg({
    'Recession': 'first',
    'GDP Growth': ['size', 'sum']
}).reset_index()

recession_data.columns = ['Recession Start', 'Recession', 'Duration', 'Severity']

# Plot Duration and Severity of Recession
fig = px.bar(recession_data, x='Recession Start', y=['Duration', 'Severity'],
             title='Duration and Severity of Recession',
             labels={'value': 'Duration/Severity', 'variable': 'Metric'},
             color='Recession', color_discrete_map={False: 'green', True: 'red'})

# Update the layout
fig.update_layout(xaxis_title='Recession Periods', yaxis_title='Duration/Severity')

fig.show()

Recession tells us whether the economy is doing well or not in each quarter. When Recession is True, it means the economy is going through a tough time during that quarter. The code defines a tough time as having negative growth in both the current quarter and the one before it. When Recession is False, it means things are generally okay during that quarter. The code then looks at different aspects of these tough times, like how long they last (Recession Duration) and how severe they are (Recession Severity). This helps us understand more about the ups and downs in the economy over time.¶

In [ ]: